/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Service;

import Util.TranslatorUtils;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Peat
 */
public class MainService extends BaseService {

    public HttpServletResponse doLogin(
           HttpServletRequest httpRequest) throws NamingException
    {
//        this.readyEJB(null);

        String username = httpRequest.getParameter("username");
        String password = httpRequest.getParameter("password"); //FIXME
        HttpSession session = httpRequest.getSession();

        // LOGIN
        if (password.equals("1234")) {
            session.setAttribute("username", username);     // this one will be accessed at UI level.
            session.setAttribute("InfoSubscriber", TranslatorUtils.toServerPhoneNumber(username));
            session.setAttribute("InfoAuthenBean", "something");
            logger.info("Login -- SUCCESS");
        } else {
            session.removeAttribute("username");
            session.removeAttribute("InfoSubscriber");
            session.removeAttribute("InfoAuthenBean");
            logger.info("Login -- FAILED");
        }
        return null;
    }

    public HttpServletResponse doLogout(
           HttpServletRequest httpRequest) throws NamingException {
        HttpSession session = httpRequest.getSession();

        session.removeAttribute("username");
        session.removeAttribute("InfoSubscriber");
        session.removeAttribute("InfoAuthenBean");

        return null;
    }

}
